<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>

    <style>
        .box {
            width: 100px;
            height: 1000px;
            background-color: aqua;
        }
    </style>
</head>

<body>
    <div class="box"></div>
    <img alt="">

    <script>
        const img = document.querySelector('img')

        const observer = new IntersectionObserver((arr) => {
            console.log(111)
            // 进入可是去\ 离开可视区会自动触发改函数
            console.log('查看上面的属性', arr[0])

            if (arr[0].isIntersecting) {
                console.log('img进入可视区了')
                img.src = "./src/assets/svg一览图/svg.png"

                observer.disconnect() //移除监听
            }
        })

        observer.observe(img)
    </script>
</body>

</html>